<?php
namespace Admin\Controller;

use Common\Controller\AdminbaseController;
class FragController extends AdminbaseController{
	

	
	function _initialize() {
		parent::_initialize();
		$this->db = D("Frag");
	
	}
	
	function index(){
	
	
	
		$list=$this->db->order(array("id"=>"DESC"))->select();
		
		
		
		$this->assign("_list",$list);
		$this->display();
		
		
		
		
	
	}
	

	
	function add(){
		
		if(IS_POST){
			if ($this->db->create($_POST)) {
				if ($this->db->add()!==false) {
					$this->success("添加成功！", U("index"));
				} else {
					$this->error("添加失败！");
				}
			} else {
				$this->error($this->db->getError());
			}
		}else{
		
		
		
		
		$this->display("form");
		}
		}
	
	
	function edit(){
		
		
		if(IS_POST){
			if ($this->db->create($_POST) ){
				
				if ($this->db->save()!==false) {
					$this->success("保存成功！", U("index"));
				} else {
					$this->error("保存失败！");
				}
			} else {
				$this->error($this->db->getError());
			}
		
		}else{
	
		$id= intval(I("get.id"));
		if(!$id){
			$this->error("缺少参数！");
		}
	
		
		$r=$this->db->where("id=$id")->find();
		
	
		
		
		$this->assign("edit",true);
		$this->assign("data",$r);
	
	
		$this->display("form");
		}
	}
	

	
	

	function delete(){
		if(isset($_GET['id'])){
			$id = intval(I("get.id"));
	

			if ($this->db->delete($id)) {
					$this->success("删除成功！");
			} else {
				$this->error("删除失败！");
			}
		}
		if(isset($_POST['ids'])){
			$ids=I("param.ids");
	
			$map[id]=array("in",$ids);
	
			if ($this->db->where($map)->delete()) {
				$this->success("删除成功！");
			} else {
				$this->error("删除失败！");
			}
		}
	}
	

	
	
	
	}